package com.jt.utils;

import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import org.springframework.stereotype.Component;

@Component
public class OkhttpUtil {
    public String post(String url,String json,String  token) {
        String result="";
        try {
            OkHttpClient client = new OkHttpClient().newBuilder()
                    .build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(mediaType, json );
            Request request = new Request.Builder()
                    .url(url)
                    .method("POST", body)
                    .build();
            Response responsebady = client.newCall(request).execute();
            System.out.println("responsebady==="+responsebady);
            JSONObject  jsonObject=new JSONObject();
            result = jsonObject.toJSONString(responsebady.body());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("异常");
        }
        System.out.println("采集数据result==="+result);
        return  result;
    }

}
